<template>
	<view>
		<view class="repair-card" @click="jumpDetail(item.id)" v-for="(item,index) in propsList.list" :key='item.id'>
			<view class="card-title">
				<view class="" style="flex:1">
					{{item.hospital.name}}
				</view>
				<view class="" style="color: #FFAB00;font-size: 28rpx;" >
					<text v-if="item.status==2">待验收</text>

					<text v-if="item.status==2" style="color: #DADADA;">  {{' '}}| {{'  '}}</text>
					<text>{{item.type_data}}</text>

				</view>
			</view>
			<view class="card-content">
				<image src="../static/finiash.png" v-if="item.status==3" class="finiash" mode=""></image>
				<view class="card-content-item">
					设备名称：<text class="attribute">{{item.equipment.name||'暂无信息'}}</text>
				</view>
				<view class="card-content-item">
					型号：<text class="attribute">{{item.equipment.marking||'暂无信息'}}</text>
				</view>
				<view class="card-content-item">
					序列号：<text class="attribute">{{item.equipment.serial||'暂无信息'}}</text>
				</view>
				<view class="card-content-item" v-if="item.commiss_sale != 0">
					销售提成次数：<text class="attribute">{{item.commiss_sale ||'暂无信息'}}</text>
				</view>
				<view class="card-content-item" v-if="item.commiss_eng != 0">
					工程师提成次数：<text class="attribute">{{item.commiss_eng ||'暂无信息'}}</text>
				</view>
				<view class="card-content-item">
					收款状态：<text class="attribute">{{item.collect_data == 0 ? '应收订单' : '已收款订单'}}</text>
				</view>
				<view class="card-content-item">
					暂停状态：<text class="attribute">{{item.open_data == 0 ? '暂停' : '开启'}}</text>
				</view>
				<view class="card-content-item">
					亏损状态：<text class="attribute">{{item.is_loss == 1 ? '亏损' : '正常'}}</text>
				</view>
				<view class="card-content-item">
					板件工程师：<text class="attribute">{{item.engineer.nickname||'暂无'}}</text>
				</view>
				<view class="card-content-item">
					外勤工程师：<text class="attribute">{{item.engineer.fieldengineer||'暂无'}}</text>
				</view>
				<view class="card-content-item">
					工单ID：<text class="attribute">{{item.workID||'暂无信息'}}</text>
				</view>
				<view class="card-content-item" v-if="item.next_time">
					下次维保时间：<text class="attribute">{{item.next_time||'暂无信息'}}</text>
				</view>
				<view class="card-content-item" v-if="item.progress">
					维保次数：<text class="attribute">{{item.progress||'暂无信息'}}</text>
				</view>
				<view class="card-content-item" v-if="type == 'purchase'">
					采购状态：<text class="attribute">{{item.purchase_status||'无采购'}}</text>
				</view>
			</view>
			<view class="card-time">
				<view class="card-time-left">
					{{item.createtime}}
				</view>
				<view class="card-time-right" v-if="from==1" @tap.stop="getContact(item)">
					关联配件
				</view>
				<view>
					<view v-if="item.zyzds_file && item.zyzds_file.length > 0" class="card-time-right" style="margin-bottom: 10rpx;" @click.stop="jumpInstructor(item)" >
						指导书
					</view>
					<view class="card-time-right" >
						详情
					</view>
				</view>
			</view>
		</view>
		<u-modal :show="show" title="请输入数量" @confirm="showConfirm(item)" @cancel="show=false" showCancelButton>
			<u--input placeholder="请输入数量" v-model="num" border="surround" clearable type="number"></u--input>
		</u-modal>
	</view>
</template>

<script>
	export default {
		name: "orderCard",
		/* 
		propsList.type：
		repair   维保工单 
		checkout   待验收
		*/
		props: {
			propsList: Object,
			from:{
				type:Number,
				default:0
			},
			inventoryId:{
				type:String|Number,
				default:0
			},
			type: {
				type: String,
				default: ''
			}
		},
		data() {
			return {
				show:false,
				num:0,
				inventInfo:{}
			}
		},
		methods: {
			jumpDetail(id) {
				this.$emit('detail', id)
			},
			getContact(item){
				this.num = 0
				this.inventInfo.inventory_log_id = this.inventoryId
				this.inventInfo.warranty_id = item.id
				this.show = true
			},
			// 预览指导书
			jumpInstructor(item) {
				let itemList = JSON.parse(JSON.stringify(item.zyzds_file))
				uni.showActionSheet({
					itemList: itemList.map(v => v.split('/').pop()),
					success: (res) => {
						uni.downloadFile({
							url: item.zyzds_file[res.tapIndex],
							success: (res) => {
								uni.openDocument({
									filePath: res.tempFilePath,
									showMenu: false,
									fail: (err) => {
										uni.showToast({
											title: '打开指导书失败',
										})
									}
								})
							}
						})
					}
				})
			},
			// 绑定工单
			showConfirm() {
				this.inventInfo.num = this.num
				this.$https
					.get("/inventory/bind", this.inventInfo)
					.then((res) => {
						if(res.code == 1){
							uni.showToast({
								title: res.msg,
								icon: 'none',
								duration: 1500
							})
							this.show = false
						}else{
							
						}
					})
					.catch(() => {
						// this.changeLoadStratus();
					});
			},
		}
	}
</script>

<style lang="scss" scoped>
	.repair-card {
		background-color: #FFFFFF;

		border-radius: 8rpx;
		margin-bottom: 20rpx;

		.card-title {
			padding: 22rpx 20rpx;
			font-size: 32rpx;
			font-family: PingFang SC-Semibold, PingFang SC;
			font-weight: 600;
			color: #303030;
			display: flex;
			justify-content: space-between;
		}

		.card-content {
			position: relative;
			display: flex;
			flex-wrap: wrap;
			padding: 32rpx 20rpx;
			border-top: 2rpx solid #f7f8fb;
			border-bottom: 2rpx solid #f7f8fb;
			font-size: 24rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #969699;

			.finiash {
				position: absolute;
				width: 80rpx;
				height: 80rpx;
				right: 30rpx;
				top: -80rpx;
				transform: rotate(-8deg);
			}

			.card-content-item {
				width: 50%;

				.attribute {
					display: inline-block;
					color: #303030;
					margin-bottom: 12rpx;
				}
			}
		}

		.card-time {
			font-size: 24rpx;
			font-family: PingFang SC-Regular, PingFang SC;
			font-weight: 400;
			color: #646466;
			padding: 22rpx 20rpx;
			display: flex;
			justify-content: space-between;
			align-items: center;

			.card-time-left {}

			.card-time-right {
				font-size: 28rpx;
				font-family: PingFang SC-Regular, PingFang SC;
				font-weight: 400;
				text-align: center;
				color: $public-oclor;
				padding: 6rpx 32rpx;
				border-radius: 32rpx;
				opacity: 1;
				border: 2px solid $public-oclor;
			}
		}
	}
</style>
